#include "touch_event.h"

KTouchEventRingBuffer::KTouchEventRingBuffer()
{
	Reset();
}

void KTouchEventRingBuffer::Reset()
{
	mStartIdx = 0;
	mEventCnt = 0;
}

void KTouchEventRingBuffer::PushEvent(KTouchEvent::TouchType type, const KVec2& pos)
{
	mRingBuf[mStartIdx].type = type;
	mRingBuf[mStartIdx].pos = pos;
	++mStartIdx;
	++mEventCnt;
	mStartIdx %= cRingBufLen;
	if (mEventCnt > cRingBufLen) 
		mEventCnt = cRingBufLen;
}

int KTouchEventRingBuffer::GetEventCount() const
{
	return mEventCnt;
}

const KTouchEvent& KTouchEventRingBuffer::GetEvent(int idx) const
{
	return mRingBuf[(mStartIdx + cRingBufLen - idx - 1) % cRingBufLen];
}